<!-- 创伤MPDS页面 -->

<template>
  <div id="box">
    <div class="mpds-trauma">
      <el-row :gutter="24">
        <el-col :span="24">
          <div class="fr">
            <span class="mr-10">{{ creatTime }}</span>
            <span class="mr-10">{{ creatDoc }}</span>
            <span class="mr-10">
              <el-button type="primary" size="small" @click="saveInfo">保存</el-button>
            </span>
          </div>
        </el-col>
        <el-col :span="24">
          <h3 class="fl">MPDS</h3>
        </el-col>
        <el-col :span="24">
          <el-checkbox-group v-model="MPDS">
            <el-checkbox label="mpds0">交通/运输事故</el-checkbox>
            <el-checkbox label="mpds1">高处坠落</el-checkbox>
            <el-checkbox label="mpds2">暴力袭击/侵犯</el-checkbox>
            <el-checkbox label="mpds3">动物咬伤/攻击</el-checkbox>
            <el-checkbox label="mpds4">烧伤(烫伤)爆炸伤</el-checkbox>
          </el-checkbox-group>
        </el-col>
        <el-col :span="24">
          <el-checkbox-group v-model="MPDS">
            <el-checkbox label="mpds5">锐器刺伤/枪伤/贯穿伤</el-checkbox>
            <el-checkbox label="mpds6">触电/雷击伤</el-checkbox>
            <el-checkbox label="mpds7">冬季运动损伤</el-checkbox>
            <el-checkbox label="mpds8">机械损伤</el-checkbox>
            <el-checkbox label="mpds9">创伤(其他创伤)</el-checkbox>
          </el-checkbox-group>
        </el-col>
        <el-col :span="24">
          <h3 class="fl">病情判断</h3>
        </el-col>
        <el-col :span="24">
          <el-radio-group v-model="diagnoseContent">
            <el-radio label="0">非急</el-radio>
            <el-radio label="1">亚急</el-radio>
            <el-radio label="2">急症</el-radio>
            <el-radio label="3">危重</el-radio>
            <el-radio label="4">濒危</el-radio>
            <el-radio label="5">已死亡</el-radio>
          </el-radio-group>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import { findDiagnoses, diagnosesList } from '@/api/green-channel/mpdsTrauma'
import format from '@/utils/format'
export default {
  // eslint-disable-next-line vue/require-prop-types
  props: ['checkrowdata'], // 由主页面(父组件) 接收来的, 选择项的数据
  data() {
    return {
      creatTime: '',
      creatDoc: '',
      MPDS: [],
      diagnoseContent: '',
      mpdsInfo: null
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.mpdsInfo = null
      findDiagnoses({
        dispatchId: this.checkrowdata.dispatchId
      }).then(res => {
        if (res && res.length > 0) {
          res.forEach(el => {
            let mpdsData = []
            if (el.diagnoseType == 'MPDS') {
              this.creatTime = el.updatedAt
              this.creatDoc = el.user
              if (el.diagnoseContent) {
                mpdsData = JSON.parse(el.diagnoseContent)
              }
              this.MPDS = mpdsData
              this.diagnoseContent = el.grade
              this.mpdsInfo = el
            }
          })
        }
      })
    },
    saveInfo() {
      const nowTime = format(new Date(), 'YYYY-MM-DD HH:mm:ss')
      const mpdsData = JSON.stringify(this.MPDS)
      diagnosesList([{
        createdAt: this.mpdsInfo.createdAt,
        department: this.mpdsInfo.department,
        diagnoseContent: mpdsData,
        diagnoseName: null,
        diagnoseTime: null,
        diagnoseType: 'MPDS',
        dispatchId: this.mpdsInfo.dispatchId,
        grade: this.diagnoseContent,
        id: this.mpdsInfo.id,
        killipLevel: null,
        medicalId: this.mpdsInfo.medicalId,
        remarks: '',
        score: null,
        strokeDiagnosisName: null,
        strokeDiagnosisType: null,
        updatedAt: nowTime,
        user: this.mpdsInfo.user,
        userId: this.mpdsInfo.userId
      }]).then(res => {
        if (res.code == 0) {
          this.$message({
            type: 'success',
            message: '保存成功'
          })
          this.init()
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
#box {
  width: 100%;
  height: 100%;
  padding: 10px 20px;
  .mpds-trauma{
    width: 100%;
    background-color: #f9f9f9;
    margin-top: 10px;
    padding: 10px;
  }
}
</style>
